//第一种方式
/*
package main

import (
	"fmt"
	"net/http"
)

type MyMux struct {
}

func (p *MyMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == "/" {
		sayhelloName(w, r)
		return
	}
	http.NotFound(w, r)
	return
}

func sayhelloName(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello MyMuxRoute!")
}

func main() {
	mux := &MyMux{}                   //&结构体方式
	http.ListenAndServe(":8080", mux) //mux是核心操作代码
}

*/

//第二种方式
package main

import (
	"fmt"
	"net/http"
)

type MyMux struct {
}

func (p *MyMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == "/" {
		sayhelloName(w, r)
		return
	}
	http.NotFound(w, r)
	return
}

func sayhelloName(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello MyMuxRoute!")
}

//新建的&结构体方法，框架中十分常用
func NewMyMux() *MyMux {
	return &MyMux{} //等同于  return new(MyMux)
}

func main() {
	mux := NewMyMux()                 //通过调用一个方法来实现
	http.ListenAndServe(":8080", mux) //mux是核心代码
}
